package com.nku.mason.scm.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nku.mason.scm.service.GoodsService;
import com.nku.mason.scm.vo.Goods;
import com.nku.mason.scm.vo.PageBean;

@Controller
@RequestMapping("/goods")
public class GoodsAction{
	@Resource
	private GoodsService goodsService;
	
	@RequestMapping("/selectPage")
	@ResponseBody
	public Object selectPage(PageBean<Goods> page , Goods goods){
		System.out.println("-----selectPage.page" + page);
		System.out.println("-----selectPage.goods" + goods);
		page.setParamEntity(goods);
		try {
			page = goodsService.selectPage(page);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page.getPageMap();
	}
	
	@RequestMapping("/deleteByPks")
	@ResponseBody
	public Object deleteByPks(String [] pks) {
		System.out.println("---deleteByPks.pks:" + pks);
		int i = 0;
		try {
			i = goodsService.deleteByPks(pks);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	
	@RequestMapping("/insert")
	@ResponseBody
	public Object insertGoods(Goods goods){
		System.out.println("---insertGoods:" + goods);
		int i = 0;
		try {
			i = goodsService.insert(goods);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public Object updateGoods(Goods goods){
		System.out.println("---updateGoods:" + goods);
		int i = 0;
		try {
			i = goodsService.update(goods);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
}
